#include "stdafx.h"
#include "CppUnitTest.h"

#include <HSModel/SharedConstants.h>
#include <HSModel/GameConstants.h>
#include <HSModel/GameController.h>
#include <HSModel/Ground.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace HSModelTests
  {
  TEST_CLASS(GameControllerTests)
    {
    public:
      TEST_METHOD(TestStartingAmountOfMoney)
        {
        GameController control;
        Assert::AreEqual(GameConstants::STARTING_MONEY, control.GetMoney());
        }

      TEST_METHOD(TestTreeCanNotBePlacedWhenNotEnoughMoney)
        {
        GameController control;
        control.SetMoney(GameConstants::TREE_COST - 1);

        Assert::IsFalse(control.CanPlaceTree());
        }

      TEST_METHOD(TestWalkwayCreatingDecreasesMoneyByAConstantAmount)
        {
        GameController control;
        int money = control.GetMoney();
        control.WalkwayCreated();

        Assert::AreEqual(money - GameConstants::WALKWAY_COST, control.GetMoney());
        }

      TEST_METHOD(HappinessMustBeIn01Range)
        {
        GameController control;
        HeightMap height_map = HeightMap(GroundConstants::HEIGHTMAP_SIZE, GroundConstants::HEIGHTMAP_SIZE);
        GeneratedHeightMapWithDiamondSquare(height_map, GroundConstants::PLAINS_PERCENTAGE, GroundConstants::MAX_HEIGHT);
        Ground ground = Ground(height_map, GroundConstants::CELL_SIZE, GroundConstants::WATER_LEVEL);
        control.LandscapeChanged(ground);
        double result = control.GetHappiness();

        Assert::IsTrue(0 <= result && result <= 1);
        }

      TEST_METHOD(BenchCanNotBePlacedWhenNotEnoughMoney)
        {
        GameController control;
        control.SetMoney(GameConstants::BENCH_COST - 1);

        Assert::IsFalse(control.CanPlaceBench());
        }

      TEST_METHOD(BenchCreationDecreasesMoney)
        {
        GameController control;
        int money = control.GetMoney();
        control.BenchPlaced();

        Assert::AreEqual(money - GameConstants::BENCH_COST, control.GetMoney());
        }

      TEST_METHOD(GameControllerLosingMoneyTest)
        {
        GameController control;
        int starting_money = 1000;
        control.SetMoney(starting_money);
        control.SetHumanCount(0);
        control.FerrisWheelPlaced(false);

        control.MakeProfit();

        int result = control.GetMoney();
        Assert::IsTrue(result < starting_money);
        }

      TEST_METHOD(GameControllerMakingMoneyTest)
        {
        GameController control;
        int starting_money = 1000;
        control.SetMoney(starting_money);
        control.SetHumanCount(GameConstants::FERRIS_WHEEL_HUMAN_CAPACITY);
        control.FerrisWheelPlaced(false);

        control.MakeProfit();

        int result = control.GetMoney();
        Assert::IsTrue(result > starting_money);
        }
    };
  }